// 新建网络处理类
package com.xie.smfs.network;

import com.xie.smfs.common.events.PlayerEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class SpiritNetworkHandler {
    public static final Identifier SYNC_SPIRIT_DATA = new Identifier("smfs", "sync_spirit_data");

    public static void registerReceivers() {
        // 如果需要客户端向服务器发送数据，可以在这里注册
    }

    public static void syncSpiritData(ServerPlayerEntity player) {
        NbtCompound spiritData = PlayerEvents.getSpiritAttributes(player);
        PacketByteBuf buf = PacketByteBufs.create();
        buf.writeNbt(spiritData);

        ServerPlayNetworking.send(player, SYNC_SPIRIT_DATA, buf);
    }
}